package com.qincji.webviewbrowser;

import ohos.aafwk.ability.Ability;
import ohos.aafwk.content.Intent;
import ohos.aafwk.content.Operation;
import ohos.utils.net.Uri;

/**
 * 描述：
 * 作者：qincji on 2021/7/8 16:56
 * 起于：https://zqxq.club
 * 邮箱：xhunmon@126.com
 */
public class AppKit {

    public static void openInBrowser(Ability ability, String url) {
        Intent intent = new Intent();
        Operation operation = new Intent
                .OperationBuilder()
                .withAction("android.intent.action.VIEW")
                .withUri(Uri.parse(url))
                .build();
        intent.setOperation(operation);
        ability.startAbility(intent);
    }

    public static void shareText(Ability ability, String shareText) {
        Intent intent = new Intent();
        Operation operation = new Intent
                .OperationBuilder()
                .withAction("android.intent.action.SEND")
                .withFlags(0x10000000)
                .build();
        intent.setType("text/plain");
        intent.setParam("android.intent.extra.SUBJECT", "分享");
        intent.setParam("android.intent.extra.TEXT", shareText);
        intent.setOperation(operation);
        ability.startAbility(intent);
    }

    public static void shareImage(Ability ability, Uri uri) {
        Intent intent = new Intent();
        Operation operation = new Intent
                .OperationBuilder()
                .withAction("android.intent.action.SEND")
                .withFlags(0x10000000)
                .build();
        intent.setParam("android.intent.extra.STREAM", uri);
        intent.setType("image/jpeg");
        intent.setOperation(operation);
        ability.startAbility(intent);
    }
}
